var gulp = require("gulp");
var plumber = require("gulp-plumber");
var changed = require("gulp-changed");
var babel = require("gulp-babel");
var sourcemaps = require("gulp-sourcemaps");
var del = require("del");

var source = "src/**/*.js";
var target_directory = "build";

gulp.task("babel", function() {
    return gulp.src(source)
        .pipe(changed(target_directory))
        .pipe(plumber())
        .pipe(sourcemaps.init())
            .pipe(babel({presets: ["es2015", "stage-0"]}))
        .pipe(sourcemaps.write("."))
        .pipe(gulp.dest(target_directory));
});

gulp.task("watch", function() {
    gulp.watch(source, ["babel"]);
});

gulp.task("clean", function(callback) {
    del(["build"], callback);
})

gulp.task("default", ["babel"]);
